<script>
export default {
  name: "DragTool",
  props: {
    schema: {
      type: Object,
      default: null,
    },
  },
  inject: ["main"],
  render() {
    let active = null;
    if (
      this.main.selectSchema &&
      this.schema.id === this.main.selectSchema.id
    ) {
      active = "active";
    }

    function handleSelect(schema) {
      this.main.handleSelectSchema(schema);
    }
    // <div class={["drag-mask"]}></div>
    return (
      <div
        class={["drag-tool", active]}
        onClick={(e) => {
          e.stopPropagation();
          handleSelect.call(this, this.schema);
        }}
      >
        <div class={["drag-l"]}>
          <div
            class={["drag-btn el-icon-rank drag-handle "]}
            style={{ cursor: "move" }}
          ></div>
        </div>
        <div class={["drag-r"]}>
          <span
            class={["drag-btn el-icon-copy-document"]}
            onClick={() => {
              this.main.copy(this.schema);
            }}
            title="复制"
          ></span>
          <span
            class={["drag-btn el-icon-delete"]}
            onClick={() => {
              this.main.delete(this.schema.id);
            }}
            title="删除"
          ></span>
        </div>
        {this.$slots.default}
      </div>
    );
  },
};
</script>

<style lang="scss" scoped>
.drag-tool {
  word-wrap: break-word;
  box-sizing: border-box;
  min-height: 20px;
  outline: 1px dashed #2e73ff;
  overflow: hidden;
  padding: 2px;
  position: relative;
  word-break: break-all;
}
.drag-tool + .drag-tool {
  margin-top: 6px;
}
.drag-tool.active {
  outline: 2px solid #2e73ff;
}
.drag-tool.active > div > .drag-btn {
  display: flex;
}

.drag-tool .drag-btn {
  display: none;
}
.drag-mask {
  bottom: 0;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
  //   z-index: 1900;
}
.drag-l,
.drag-r {
  position: absolute;
  z-index: 1904;
}

.drag-l {
  left: 0;
  top: 0;
}

.drag-r {
  top: 2px;
  right: 2px;
}

.drag-btn {
  background-color: #2e73ff;
  color: #fff;
  cursor: pointer;
  float: left;
  height: 18px;
  justify-content: center;
  line-height: 20px;
  padding-bottom: 1px;
  text-align: center;
  width: 18px;
}

.action-group {
  position: absolute;
  top: 0;
  right: 20px;
  z-index: 10;
  cursor: pointer;
  line-height: 17px;
}

.drag-tool .drag-tool {
  margin: 5px;
}
</style>
